home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / FREXP.C < prev    next >
Text File  |  1992-03-01  |  742b  |  34 lines

  1. /*
  2.  * frexp - floating point analysis.
  3.  * Intel iAPX*87 IEEE floating point version.
  4.  *
  5.  * (C) Copyright 1991 Diomidis Spinellis <dds@doc.ic.ac.uk>.
  6.  *
  7.  * May be freely copied according to the GNU general public license.
  8.  *
  9.  */
  10.  
  11. double
  12. frexp(double x, int *exptr)
  13. {
  14.     union {
  15.         double d;
  16.         unsigned char c[8];
  17.     } u;
  18.  
  19.     u.d = x;
  20.     /*
  21.      * The format of the number is:
  22.      * Sign, 12 exponent bits, 51 mantissa bits
  23.      * The exponent is 1023 biased and there is an implicit zero.
  24.      * We get the exponent from the upper bits and set the exponent
  25.      * to 0x3fe (1022).
  26.      */
  27.     *exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
  28.     u.c[7] &= 0x80;
  29.     u.c[7] |= 0x3f;
  30.     u.c[6] &= 0x0f;
  31.     u.c[6] |= 0xe0;
  32.     return u.d;
  33. }
  34.